﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

namespace HZ.Supervise.Web.TotalDrugs
{
    public partial class ReportL : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                txtStratTime.Text = DateTime.Now.AddMonths(-1).ToString("yyyy-MM-dd");
                txtEndTime.Text = DateTime.Now.AddMonths(-1).ToString("yyyy-MM-dd");
            }
        }
        /// <summary>
        /// 绑定数据
        /// </summary>
        public void BindData()
        {
            int totalrecord = 0;
            DataTable dt = new HZ.Supervise.BLL.SuperviseContext().GetReportL(str(), this.AspNetPager_CompanyPS.CurrentPageIndex, AspNetPager_CompanyPS.PageSize, out totalrecord);
            AspNetPager_CompanyPS.RecordCount = totalrecord;
            gvwInfo.PageSize = AspNetPager_CompanyPS.PageSize;
            gvwInfo.DataSource = dt;
            gvwInfo.DataBind();
        }
        /// <summary>
        /// 查询条件
        /// </summary>
        string str()
        {
            string s = "";
            if (!string.IsNullOrEmpty(txtStratTime.Text.Trim()))
            {
                s += string.Format(@" AND SubmiTime >= '{0}'", txtStratTime.Text.Trim());
            }
            if (!string.IsNullOrEmpty(txtEndTime.Text.Trim()))
            {
                s += string.Format(@" AND SubmiTime < '{0}'", Convert.ToDateTime(txtEndTime.Text.Trim()).AddDays(1));
            }
            return s;
        }

        protected void btnQuery_Click(object sender, EventArgs e)
        {
            this.AspNetPager_CompanyPS.CurrentPageIndex = 1;
        }

        protected void btnExcel_Click(object sender, EventArgs e)
        {
            try
            {
                int totacount = 0;
                DataTable mylist = new HZ.Supervise.BLL.SuperviseContext().GetReportL(str(), 1, int.MaxValue, out totacount);
                ExportFile.Instance.ExportData(mylist, gvwInfo, this.Page);
            }
            catch (Exception ex)
            {
                throw;
            }
        }

        protected void AspNetPager_CompanyPS_PageChanged(object sender, EventArgs e)
        {
            BindData();
        }


    }
}